<?php

namespace app\m\controller;

use app\m\controller\Base;
use think\Request;
use think\Db;
use think\Cache;
use fast\lucn\Lucn;

//use think\Db;

/**
 * 首页
 *
 * @icon fa fa-circle-o
 */
class Article extends Base
{
    protected $model = null;

    public function _initialize()
    {
		define('SIGN', 'article');//定义标识
		define('TABLE', 'article');//定义数据表名。
		$this->assign('controller_sign',SIGN);
		$this->assign('controller_page','文章');
        parent::_initialize();
    }
	
	public function tolist()
    {
		//article
		//define('TABLE_2', 'category');//定义数据表名。
		//define('PTYPE_2', '');//定义类别
		$cid = input('?cid') ? input('cid') : '';
		$category = Cache::get('cache')['category'];
		$category_article = Lucn::getCategoryFromType($category,SIGN);
		if(input('?cid')){
		    $category_one = Lucn::getCategoryFromType($category_article,$cid,'id');
			$where['category_id'] = $cid;
		}else{
		    $category_one[0]['id'] = 0;
			$category_one[0]['name'] = '新闻动态';
		}
		//dump($category_one);die;
		$where['status'] = 'normal';
	    $list = Db::name(TABLE)
		  ->where($where)
		  ->field('id,title,description,category_id,createtime,image,views')
		  ->order('id desc')
		  ->paginate(10);
         //dump($list);die;
		
		$site_title = empty($category_one) ? '新闻中心'.'_'.$this->cache['site']['name'] : $category_one[0]['name'].'_新闻中心'.'_'.$this->cache['site']['name'];
		$this->assign('list',$list); 
		$this->assign('category',$category_article); 
		$this->assign('category_one',$category_one); 
	    $this->assign('title', $site_title);
		$this->assign('keywords','');
		$this->assign('description','');
        return $this->view->fetch('/'.SIGN.'_list');
    }
	
	public function show()
	{
	    $id = input('?id') ? input('id') : 0;
		$where['id'] = $id;
		$one = Db::name(TABLE)
		  ->where($where)
		  //->field('id,title,description,category_id,author,createtime,content,views')
		  ->find();
		/*  
		$where2['id'] = array('NEQ',$id);
		$clist = Db::name(TABLE)
		  ->where($where2)
		  ->field('id,title')
		  ->order('updatetime desc')
		  ->limit(10)
		  ->select();
		*/
		
		$category = Cache::get('cache')['category'];
		$category_one = Lucn::getCategoryFromType($category,$one['category_id'],'id');
		//dump($category);die;
		
		$site_title = $one['title'].'_'.$this->cache['site']['name'];
		$this->assign('one',$one); 
		//$this->assign('clist',$clist); 
		$this->assign('category_one',$category_one); 
	    $this->assign('title',$site_title);
		$this->assign('mobile_url',__ROOT__);
		$this->assign('keywords','');
		$this->assign('description','');
        return $this->view->fetch('/'.SIGN.'_show');
	}
}
